package cn.darkhorse.ticket.basis.service.impl;

import cn.darkhorse.ticket.basis.mapper.TicketRoutingMapper;
import cn.darkhorse.ticket.basis.pojo.TicketProcedure;
import cn.darkhorse.ticket.basis.pojo.TicketProduct;
import cn.darkhorse.ticket.basis.pojo.TicketRouting;
import cn.darkhorse.ticket.basis.service.TicketProductService;
import cn.darkhorse.ticket.basis.service.TicketRoutingService;
import cn.darkhorse.ticket.constants.TicketConstants;
import cn.darkhorse.ticket.service.IRepeatCheckService;
import cn.darkhorse.ticket.basis.vo.TicketRoutingVO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 工艺路线 服务实现类
 * </p>
 *
 * @author wangxinghui
 * @since 2024-01-09
 */
@Service
public class TicketRoutingServiceImpl extends ServiceImpl<TicketRoutingMapper, TicketRouting> implements TicketRoutingService {
	
	@Resource
	private IRepeatCheckService<TicketRouting> repeatCheckService;
	@Resource
	private TicketProductService productService;
	
	
	@Override
	public String repeat(TicketRoutingVO routingVO) {
		String code = null;
		if(null==routingVO.getId()){
			code = repeatCheckService.repeatAutoCodeAndName(this, null, TicketConstants.BUSINESS_TYPE_GYLX,
					routingVO.getCode(), routingVO.getName(), routingVO.getIsAutomatically());
		}else {
			repeatCheckService.repeatName(this,routingVO.getId(),routingVO.getName());
		}
		return code;
	}
	
	@Override
	public boolean isQuote(String code) {
		LambdaQueryWrapper<TicketProduct> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.eq(TicketProduct::getRoutingCode,code);
		long count = productService.count(queryWrapper);
		return count>0?false:true;
	}
	
	
	
	
}
